﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess.Classes;
using DataAccess;

namespace Webmau.Controls
{
    public partial class DangNhap : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            NguoiDung1 nguoidung = NguoiDung1.LayThongTinNguoiDung(txtTenDangNhap.Text);
            if (nguoidung == null)
            {
                lbThongBao.Text = "Sai tên đăng nhập";
            }
            if (nguoidung != null)
            {
                if (nguoidung.MaNhom == "N01")
                {
                    if (nguoidung.MatKhau == MaHoaMatKhau.GetMD5(txtMatKhau.Text))
                    {
                        Session["id"] = nguoidung.IDNguoiDung;
                        Session["ten"] = nguoidung.TenNguoiDung;
                        Session["manhom"] = nguoidung.MaNhom;
                        Session["matkhau"] = nguoidung.MatKhau;
                        Response.Redirect("Default.aspx");
                    }
                    if (nguoidung.MatKhau != MaHoaMatKhau.GetMD5(txtMatKhau.Text))
                    {
                        lbThongBao.Text = "Sai mật khẩu";
                    }
                }
                if (nguoidung.MaNhom != "N01")
                {
                    if (nguoidung.MatKhau == MaHoaMatKhau.GetMD5(txtMatKhau.Text))
                    {
                        Session["id"] = nguoidung.IDNguoiDung;
                        Session["ten"] = nguoidung.TenNguoiDung;
                        Session["manhom"] = nguoidung.MaNhom;
                        Response.Redirect("Default.aspx");
                    }
                    if (nguoidung.MatKhau != MaHoaMatKhau.GetMD5(txtMatKhau.Text))
                    {
                        lbThongBao.Text = "Sai mật khẩu";
                    }
                }
            }
        }
    }
}
